package com.du.managerback.controller;


import com.du.managerback.entily.Employee;
import com.du.managerback.exception.CustomException;
import com.du.managerback.service.EmployeeService;
import com.du.managerback.utils.BaseResult;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;


@RestController
public class Hello {
    @Autowired
    EmployeeService employeeService;
//    @GetMapping("/hello")
//    public BaseResult hello() {
//        isInt(30,"张三");
//        return BaseResult.success("服务器数据");
//    }
//    @GetMapping("/age")
//    public BaseResult getAge() {
//        throw new CustomException("502","服务器现在业务出问题");
//    }
//    @GetMapping("/map")
//    public BaseResult getInfo() {
//        HashMap<String, String> map = new HashMap<>();
//        map.put("name", "张三");
//        map.put("password", "root");
//        map.put("age", "18");
//        return BaseResult.success(map);
//    }
//    public String userName="zhangsan";
//    public boolean isSchool=false;
//    public int age=20;
//
//    //定义函数  功能 返回值 函数名 形参
//    public String isInt(int a, String b){
//        if (a>20){
//            System.out.println("年龄为"+age);
//        }
//        return "2";
//    }

    //创建类的实例
//    public void test(){
//        int age=20;
//        Student zhansan=new Student("张三", "001");
//        zhansan.study();
//        System.out.println(zhansan.getNo());
//
//    }
    @GetMapping("/getAll")
    public BaseResult getAll(@RequestParam(defaultValue = "1") Integer pageNum,@RequestParam(defaultValue = "10") Integer pageSize){

        PageInfo<Employee> employeePageInfo=employeeService.setAll(pageNum,pageSize);
        return BaseResult.success(employeeService.setAll(pageNum,pageSize));
    }
    @GetMapping("/selectById/{id}")
    public BaseResult selectById(@PathVariable("id") Integer id) {
        return BaseResult.success(employeeService.selectById(id));
    }



}
